--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
tests/backend/test_async_utils_critical.py v4.7.0-rc.4 (448cd46c) Text, 2.85 KB
T8b949e# SPDX-License-Identifier: 0BSD
T8b949e"""Critical-path tests for ``AsyncUtils``: cross-thread scheduling and memory caps."""
Tff7b72from T7ee787__future__ Tff7b72import Te6edf3annotations
Tff7b72import T7ee787asyncio
Tff7b72import T7ee787threading
Tff7b72import T7ee787warnings
Tff7b72import T7ee787pytest
Tff7b72from T7ee787meshchatxT7ee787.T7ee787srcT7ee787.T7ee787backendT7ee787.T7ee787async_utils Tff7b72import Te6edf3AsyncUtils
Tf0883e@pytestTff7b72.Td2a8fffixtureTb4b4b4(Te6edf3autouseTff7b72=Tff7b72TrueTb4b4b4)
Tff7b72def Td2a8ff_reset_async_utilsTb4b4b4(Tb4b4b4)Tb4b4b4:
Te6edf3AsyncUtilsTff7b72.Td2a8ffmain_loop Tff7b72= Tff7b72None
Te6edf3AsyncUtilsTff7b72.Td2a8ff_pending_futuresTff7b72.Td2a8ffclearTb4b4b4(Tb4b4b4)
Te6edf3AsyncUtilsTff7b72.Td2a8ff_pending_coroutinesTff7b72.Td2a8ffclearTb4b4b4(Tb4b4b4)
Tff7b72yield
Te6edf3AsyncUtilsTff7b72.Td2a8ffmain_loop Tff7b72= Tff7b72None
Tff7b72with Te6edf3warningsTff7b72.Td2a8ffcatch_warningsTb4b4b4(Tb4b4b4)Tb4b4b4:
Te6edf3warningsTff7b72.Td2a8ffsimplefilterTb4b4b4(Ta5d6ff"Ta5d6ffignoreTa5d6ff"Tb4b4b4, Tf85149RuntimeWarningTb4b4b4)
Te6edf3AsyncUtilsTff7b72.Td2a8ff_pending_futuresTff7b72.Td2a8ffclearTb4b4b4(Tb4b4b4)
Te6edf3AsyncUtilsTff7b72.Td2a8ff_pending_coroutinesTff7b72.Td2a8ffclearTb4b4b4(Tb4b4b4)
Tff7b72async Tff7b72def Td2a8ff_noopTb4b4b4(Tb4b4b4)Tb4b4b4:
Tff7b72return Tff7b72None
Tff7b72def Td2a8fftest_buffered_coroutines_capped_when_event_loop_not_runningTb4b4b4(Tb4b4b4)Tb4b4b4:
Tff7b72with Te6edf3warningsTff7b72.Td2a8ffcatch_warningsTb4b4b4(Tb4b4b4)Tb4b4b4:
Te6edf3warningsTff7b72.Td2a8ffsimplefilterTb4b4b4(Ta5d6ff"Ta5d6ffignoreTa5d6ff"Tb4b4b4, Tf85149RuntimeWarningTb4b4b4)
Tff7b72for Te6edf3_ Tff7b72in Tffa657rangeTb4b4b4(Te6edf3AsyncUtilsTff7b72.Td2a8ff_COROUTINES_MAX Tff7b72+ T79c0ff12Tb4b4b4)Tb4b4b4:
Te6edf3AsyncUtilsTff7b72.Td2a8ffrun_asyncTb4b4b4(Te6edf3_noopTb4b4b4(Tb4b4b4)Tb4b4b4)
Tff7b72assert Tffa657lenTb4b4b4(Te6edf3AsyncUtilsTff7b72.Td2a8ff_pending_coroutinesTb4b4b4) Tff7b72== Te6edf3AsyncUtilsTff7b72.Td2a8ff_COROUTINES_MAX
Tf0883e@pytestTff7b72.Td2a8ffmarkTff7b72.Td2a8ffasyncio
Tff7b72async Tff7b72def Td2a8fftest_set_main_loop_drains_buffered_coroutinesTb4b4b4(Tb4b4b4)Tb4b4b4:
Te6edf3seenTb4b4b4: Tffa657listTb4b4b4[Tffa657boolTb4b4b4] Tff7b72= Tb4b4b4[Tb4b4b4]
Tff7b72async Tff7b72def Td2a8ffrecordTb4b4b4(Tb4b4b4)Tb4b4b4:
Te6edf3seenTff7b72.Td2a8ffappendTb4b4b4(Tff7b72TrueTb4b4b4)
Te6edf3AsyncUtilsTff7b72.Td2a8ffmain_loop Tff7b72= Tff7b72None
Te6edf3queued Tff7b72= Te6edf3threadingTff7b72.Td2a8ffEventTb4b4b4(Tb4b4b4)
Tff7b72def Td2a8ffschedule_from_workerTb4b4b4(Tb4b4b4)Tb4b4b4:
Te6edf3AsyncUtilsTff7b72.Td2a8ffrun_asyncTb4b4b4(Te6edf3recordTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3queuedTff7b72.Td2a8ffsetTb4b4b4(Tb4b4b4)
Te6edf3threadingTff7b72.Td2a8ffThreadTb4b4b4(Te6edf3targetTff7b72=Te6edf3schedule_from_workerTb4b4b4)Tff7b72.Td2a8ffstartTb4b4b4(Tb4b4b4)
Tff7b72assert Te6edf3queuedTff7b72.Td2a8ffwaitTb4b4b4(Te6edf3timeoutTff7b72=T79c0ff2.0Tb4b4b4)
Tff7b72assert Tffa657lenTb4b4b4(Te6edf3AsyncUtilsTff7b72.Td2a8ff_pending_coroutinesTb4b4b4) Tff7b72== T79c0ff1
Te6edf3AsyncUtilsTff7b72.Td2a8ffset_main_loopTb4b4b4(Te6edf3asyncioTff7b72.Td2a8ffget_running_loopTb4b4b4(Tb4b4b4)Tb4b4b4)
Tff7b72assert Te6edf3AsyncUtilsTff7b72.Td2a8ff_pending_coroutines Tff7b72== Tb4b4b4[Tb4b4b4]
Tff7b72await Te6edf3asyncioTff7b72.Td2a8ffsleepTb4b4b4(T79c0ff0.15Tb4b4b4)
Tff7b72assert Te6edf3seen Tff7b72== Tb4b4b4[Tff7b72TrueTb4b4b4]
Tf0883e@pytestTff7b72.Td2a8ffmarkTff7b72.Td2a8ffasyncio
Tff7b72async Tff7b72def Td2a8fftest_run_async_with_running_loop_executes_coroutineTb4b4b4(Tb4b4b4)Tb4b4b4:
Te6edf3outcomesTb4b4b4: Tffa657listTb4b4b4[Tffa657intTb4b4b4] Tff7b72= Tb4b4b4[Tb4b4b4]
Tff7b72async Tff7b72def Td2a8ffworkTb4b4b4(Tb4b4b4)Tb4b4b4:
Te6edf3outcomesTff7b72.Td2a8ffappendTb4b4b4(T79c0ff7Tb4b4b4)
Te6edf3AsyncUtilsTff7b72.Td2a8ffset_main_loopTb4b4b4(Te6edf3asyncioTff7b72.Td2a8ffget_running_loopTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3done Tff7b72= Te6edf3threadingTff7b72.Td2a8ffEventTb4b4b4(Tb4b4b4)
Tff7b72def Td2a8ffschedule_from_workerTb4b4b4(Tb4b4b4)Tb4b4b4:
Te6edf3AsyncUtilsTff7b72.Td2a8ffrun_asyncTb4b4b4(Te6edf3workTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3doneTff7b72.Td2a8ffsetTb4b4b4(Tb4b4b4)
Te6edf3threadingTff7b72.Td2a8ffThreadTb4b4b4(Te6edf3targetTff7b72=Te6edf3schedule_from_workerTb4b4b4)Tff7b72.Td2a8ffstartTb4b4b4(Tb4b4b4)
Tff7b72assert Te6edf3doneTff7b72.Td2a8ffwaitTb4b4b4(Te6edf3timeoutTff7b72=T79c0ff2.0Tb4b4b4)
Tff7b72await Te6edf3asyncioTff7b72.Td2a8ffsleepTb4b4b4(T79c0ff0.15Tb4b4b4)
Tff7b72assert Te6edf3outcomes Tff7b72== Tb4b4b4[T79c0ff7Tb4b4b4]
Tf0883e@pytestTff7b72.Td2a8ffmarkTff7b72.Td2a8ffasyncio
Tff7b72async Tff7b72def Td2a8fftest_pending_futures_list_sheds_completed_entriesTb4b4b4(Tb4b4b4)Tb4b4b4:
Te6edf3AsyncUtilsTff7b72.Td2a8ffset_main_loopTb4b4b4(Te6edf3asyncioTff7b72.Td2a8ffget_running_loopTb4b4b4(Tb4b4b4)Tb4b4b4)
Tff7b72with Te6edf3AsyncUtilsTff7b72.Td2a8ff_futures_lockTb4b4b4:
Te6edf3AsyncUtilsTff7b72.Td2a8ff_pending_futuresTff7b72.Td2a8ffclearTb4b4b4(Tb4b4b4)
Te6edf3finished Tff7b72= Te6edf3threadingTff7b72.Td2a8ffEventTb4b4b4(Tb4b4b4)
Tff7b72def Td2a8ffblastTb4b4b4(Tb4b4b4)Tb4b4b4:
Tff7b72for Te6edf3_ Tff7b72in Tffa657rangeTb4b4b4(Te6edf3AsyncUtilsTff7b72.Td2a8ff_FUTURES_SWEEP_THRESHOLD Tff7b72+ T79c0ff8Tb4b4b4)Tb4b4b4:
Te6edf3AsyncUtilsTff7b72.Td2a8ffrun_asyncTb4b4b4(Te6edf3asyncioTff7b72.Td2a8ffsleepTb4b4b4(T79c0ff0Tb4b4b4)Tb4b4b4)
Te6edf3finishedTff7b72.Td2a8ffsetTb4b4b4(Tb4b4b4)
Te6edf3threadingTff7b72.Td2a8ffThreadTb4b4b4(Te6edf3targetTff7b72=Te6edf3blastTb4b4b4)Tff7b72.Td2a8ffstartTb4b4b4(Tb4b4b4)
Tff7b72assert Te6edf3finishedTff7b72.Td2a8ffwaitTb4b4b4(Te6edf3timeoutTff7b72=T79c0ff5.0Tb4b4b4)
Tff7b72await Te6edf3asyncioTff7b72.Td2a8ffsleepTb4b4b4(T79c0ff0.15Tb4b4b4)
Tff7b72with Te6edf3AsyncUtilsTff7b72.Td2a8ff_futures_lockTb4b4b4:
Te6edf3still_pending Tff7b72= Tb4b4b4[Te6edf3f Tff7b72for Te6edf3f Tff7b72in Te6edf3AsyncUtilsTff7b72.Td2a8ff_pending_futures Tff7b72if Tff7b72not Te6edf3fTff7b72.Td2a8ffdoneTb4b4b4(Tb4b4b4)Tb4b4b4]
Tff7b72assert Tffa657lenTb4b4b4(Te6edf3still_pendingTb4b4b4) Tff7b72== T79c0ff0
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────